package com.unytech.wisdomcommunity.mainfragment;

import android.content.Intent;
import android.graphics.Color;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.unytech.wisdomcommunity.R;
import com.unytech.wisdomcommunity.activity.CarLifeActivity;
import com.unytech.wisdomcommunity.activity.ExpressageActivity;
import com.unytech.wisdomcommunity.activity.FreshManGuideActivity;
import com.unytech.wisdomcommunity.activity.HotlineActivity;
import com.unytech.wisdomcommunity.activity.LifePayActivity;
import com.unytech.wisdomcommunity.activity.MoreActivity;
import com.unytech.wisdomcommunity.activity.RecreationActivity;
import com.unytech.wisdomcommunity.activity.SecondaryMarketActivity;
import com.unytech.wisdomcommunity.complainrepairfragment.BaseActivity;

/**
 * Created by zed on 2016/11/7/0007.
 */
public class HomeFragment2 extends BaseFragment2 implements View.OnClickListener {
    private ImageView mComlainRepair, mLifePay, mExpressage, mRecreation, mHotline, mCarLife, mSecondaryMarket, mMore,mFreshManGuide;
    private SwipeRefreshLayout mSwipeRefreshLayout;

    @Override
    protected int getContentLayoutRes() {
        return R.layout.home_fragment;
    }

    @Override
    protected void initView(View childView) {
        //1. 投诉报修
        mComlainRepair = ((ImageView) childView.findViewById(R.id.home_complain_repair_iv));
        //生活缴费
        mLifePay = ((ImageView) childView.findViewById(R.id.home_life_pay_iv));
        //快递代收
        mExpressage = ((ImageView) childView.findViewById(R.id.home_expressage_iv));
        //休闲娱乐
        mRecreation = ((ImageView) childView.findViewById(R.id.home_recreation_iv));

        //2.  社区热线
        mHotline = ((ImageView) childView.findViewById(R.id.home_hotline_iv));
        //汽车生活
        mCarLife = ((ImageView) childView.findViewById(R.id.home_car_iv));
        //二手市场
        mSecondaryMarket = ((ImageView) childView.findViewById(R.id.home_secondary_market_iv));
        //更多
        mMore = ((ImageView) childView.findViewById(R.id.home_more_iv));

        //3.  新手指南 优惠福利  及  其他的imageview
        mFreshManGuide = (ImageView) childView.findViewById(R.id.home_fragment_freshman);

        //下拉刷新
        mSwipeRefreshLayout = (SwipeRefreshLayout) childView.findViewById(R.id.home_srl);
        mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener);
        //设置圆圈背景色
        mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Color.WHITE);
        //设置箭头颜色，可以指定多个，转一圈换一个颜色，如果到了最后一个，就回到第一个
        mSwipeRefreshLayout.setColorSchemeColors(Color.RED, Color.BLUE,Color.GREEN,Color.BLACK);

        mComlainRepair.setOnClickListener(this);
        mLifePay.setOnClickListener(this);
        mExpressage.setOnClickListener(this);
        mRecreation.setOnClickListener(this);

        mHotline.setOnClickListener(this);
        mCarLife.setOnClickListener(this);
        mSecondaryMarket.setOnClickListener(this);
        mMore.setOnClickListener(this);

        mFreshManGuide.setOnClickListener(this);
    }
    static Handler sHandler=new Handler();
    private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener = new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            //TODO 11.10 17:11 在下拉刷新的时候向服务器请求一次数据
            //刷新的圆圈 延迟三秒消失
            sHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mSwipeRefreshLayout.setRefreshing(false);
                }
            }, 4000);
        }
    };
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.home_life_pay_iv://生活缴费
                startActivity(new Intent(getActivity(), LifePayActivity.class));
                break;
            case R.id.home_complain_repair_iv://投诉报修
                startActivity(new Intent(getActivity(), BaseActivity.class));
                break;
            case R.id.home_expressage_iv://快递代收
                startActivity(new Intent(getActivity(), ExpressageActivity.class));
                break;
            case R.id.home_recreation_iv://休闲娱乐
                startActivity(new Intent(getActivity(), RecreationActivity.class));
                break;
            case R.id.home_hotline_iv://社区热线
                startActivity(new Intent(getActivity(), HotlineActivity.class));
                break;
            case R.id.home_car_iv://汽车生活
                startActivity(new Intent(getActivity(), CarLifeActivity.class));
                break;
            case R.id.home_secondary_market_iv://二手市场
                startActivity(new Intent(getActivity(), SecondaryMarketActivity.class));
                break;
            case R.id.home_more_iv://更多
                startActivity(new Intent(getActivity(), MoreActivity.class));
                break;
            case R.id.home_fragment_freshman://新手指南
                startActivity(new Intent(getActivity(),FreshManGuideActivity.class));
                break;
            default:
                Toast.makeText(getActivity(),"您的点击消失在异次元",Toast.LENGTH_SHORT).show();
                break;
        }
    }

}